package com.geor.gcv.ict.classifier;

import org.nutz.log.Loggers;
import org.slf4j.Logger;

import java.util.HashMap;
import java.util.Map;

public class Classifiers {
    static Logger log = Loggers.get();
    static Map<String, ClassifierHandler> map = new HashMap<String, ClassifierHandler>();

    public static void create(String key, String modePath, String dictPath) throws Throwable {
        try {
            ClassifierHandler handler = new ClassifierHandler();
            handler.loadDict(dictPath);
            handler.loadModel(modePath);
            map.put(key, handler);
        } catch (Throwable t) {
            log.warn(String.format("load tf model[ %s ] fail", key));
            throw t;
        }
    }

    public static void remove(String key) {
        map.remove(key);
    }

    public static ClassifierHandler get(String key) {
        return map.get(key);
    }

    public static void relese() {
        for (String key : map.keySet()) {
            map.get(key).relese();
        }
    }

}
